
$(function(){

	btn_side_txt = 'Hide Sidebar';
	btn_side_bg = '#006aeb';

	if (tools.get_cookie('sideshow') == null ||tools.get_cookie('sideshow') == 1 ) {
		$('#menu').show('display','block');
		$('#content').css('margin-left', '22em');
	}else{
		$('#menu').css('display','none');
		$('#content').css('margin-left', '1em');	
		btn_side_txt = 'Show Sidebar';
		btn_side_bg = 'green';
	}

	if (tools.check_local())
    {
        $('#breadcrumb').css('background-color','rgb(250, 122, 122)').append('<span>服务器操作，谨慎！</span>');
        $('#lang').css('background-color','rgb(250, 122, 122)');
    }else{
        $('#breadcrumb').css('background-color','rgb(206, 243, 206)');
        $('#lang').css('background-color','rgb(206, 243, 206)');
    }

	$('#breadcrumb').prepend('<a id="btn-side" href="javascript:void(0)" style="background-color:'+btn_side_bg+';color:#fff;">'+btn_side_txt+'</a>&nbsp;&nbsp;');

	$('#breadcrumb').delegate('a#btn-side', 'click', function(event) {
		event.preventDefault();
		if (tools.get_cookie('sideshow') == null ||tools.get_cookie('sideshow') == 1 ) {
			$('#menu').hide();
			$('#content').css('margin-left', '1em');
			tools.set_cookie('sideshow',0);
			$(this).text('Show Sidebar');
			$(this).css('background-color','green')
		}else{
			$('#menu').show();
			$('#content').css('margin-left', '22em');
			tools.set_cookie('sideshow',1);
			$(this).text('Hide Sidebar');
			$(this).css('background-color','#006aeb')
		}
	});
})

tools = {
	check_cookie:function(){
		if(window.navigator.cookieEnabled)  
			return true;  
		else{  
			alert("浏览器配置错误，Cookie不可用！");  
			return false;
		}  
	}
	,set_cookie:function(name,value){  
	   var Days = 30; //此 cookie 将被保存 30 天  
	   var exp = new Date(); //new Date("December 31, 9998");  
	   exp.setTime(exp.getTime() + Days*24*60*60*1000);  
	   document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();  
	}  
	,get_cookie:function(name)
	{  
		var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));  
		if(arr != null) return unescape(arr[2]); return null;  

		// var regexp = new RegExp("(?:^" + name + "|;\s*"+ name + ")=(.*?)(?:;|$)", "g");
		// var result = regexp.exec(document.cookie);
		// return (result === null) ? null : result[1];
	} 
	,check_local:function(){

		var reg1 =/^(localhost)([:]{0}\d{0,4})/	;
		var reg2 =/^192[\.0-9]*([:]\d{2,4})/;

    	if(reg1.test(location.host) || reg2.test(location.host)){
    		return false;
    	}

    	return true;
	}
}
